import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/pass_port";

export const product_info_api = (
  data: { product_id: string },
  showError = true
) => {
  return Http.get<any>(`/v1${baseUrl}/product_info`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const comment_list_data_api = (
  data: { product_id: string },
  showError = true
) => {
  return Http.get<any>(`/v1${baseUrl}/comment_list_data`, data).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const comment_list_api = (
  data: { product_id: string; type: number } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(`/v1${baseUrl}/comment_list`, data).catch(
    error => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};
